package com.aisoar.magicsoar.api.controller;

import com.aisoar.magicsoar.storage.common.valid.AddGroup;
import com.aisoar.magicsoar.storage.common.valid.EditGroup;
import com.aisoar.magicsoar.storage.common.valid.IdGroup;
import com.aisoar.magicsoar.api.service.PlaybookService;
import com.aisoar.magicsoar.storage.param.PlaybookParam;
import com.aisoar.magicsoar.storage.vo.PlaybookVO;
import com.aisoar.magicsoar.api.common.base.ApiResult;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 剧本数据表(Playbook)表控制层
 *
 * @author makejava
 * @since 2025-07-01 13:43:07
 */
@Slf4j
@RestController
@RequestMapping("/playbook")
public class PlaybookController {
    /**
     * 服务对象
     */
    @Resource
    private PlaybookService playbookService;

    /**
     * 分页查询
     *
     * @param param 选条件
     * @return 查询结果
     */
    @PostMapping("/list")
    public ApiResult<PageInfo<PlaybookVO>> queryByPage(@RequestBody PlaybookParam param) {
        return ApiResult.buildSuccessResult(this.playbookService.queryByPage(param));
    }

    /**
     * 通过主键查询详情
     *
     * @param param 入参
     * @return 单条数据
     */
    @PostMapping("/detail")
    public ApiResult<PlaybookVO> queryById(@RequestBody @Validated(IdGroup.class) PlaybookParam param) {
        return ApiResult.buildSuccessResult(this.playbookService.queryById(param));
    }

    /**
     * 新增数据
     *
     * @param param 入参
     * @return 是否成功
     */
    @PostMapping("/add")
    public ApiResult<Boolean> add(@RequestBody @Validated({AddGroup.class}) PlaybookParam param) {
        return ApiResult.buildSuccessResult(this.playbookService.insert(param));
    }

    /**
     * 编辑数据
     *
     * @param param 入参
     * @return 是否成功
     */
    @PostMapping("/edit")
    public ApiResult<Boolean> edit(@RequestBody @Validated({IdGroup.class, EditGroup.class}) PlaybookParam param) {
        return ApiResult.buildSuccessResult(this.playbookService.update(param));
    }

    /**
     * 删除数据
     *
     * @param param 入参
     * @return 删除是否成功
     */
    @PostMapping("/remove")
    public ApiResult<Boolean> deleteById(@RequestBody @Validated(IdGroup.class) PlaybookParam param) {
        return ApiResult.buildSuccessResult(this.playbookService.deleteById(param));
    }

}

